from django.shortcuts import render

from django.contrib.auth.hashers import make_password,check_password
from django.http import JsonResponse,HttpResponse
from ..models import *
from ..utils import jwtUtils
from ..utils.func import filterImageUrl, getCurrentDate, getCurrentTime
from ..utils.jsonSerialize import serialize_models
import time

from ..utils.fileSystem import uploadFileAssets


# 切换过期的优惠券状态
def refreshCouponStatus():
    # 2023-12-30 00:00:00
    currentDate = getCurrentDate()
    currentTime = getCurrentTime()
    request_data = {
        'end_time__lt': currentDate,
        'status': '1'
    }
    coupon_obj = Coupons.objects.filter(**request_data)
    coupon_obj_filter = coupon_obj.first()
    if coupon_obj_filter != None:
        print("正在更新状态")
        res = coupon_obj.update(status='2',update_time=currentTime)
        if res > 0:
            print("更新成功")
        else:
            print("更新失败")
    else:
        print("暂无更新的内容")
        pass
